package com.zhuiYun.project.api.order.service.serviceImpl;

import com.github.pagehelper.PageHelper;
import com.zhuiYun.project.api.handworkDiy.entity.HandworkDiy;
import com.zhuiYun.project.api.handworkDiy.model.HandworkDiyModel;
import com.zhuiYun.project.api.order.entity.Order;
import com.zhuiYun.project.api.order.mapper.orderMapper;
import com.zhuiYun.project.api.order.model.orderModel;
import com.zhuiYun.project.api.order.service.orderService;
import com.zhuiYun.project.util.pageUtil.MybatisPageHelper;
import com.zhuiYun.project.util.pageUtil.PageRequest;
import com.zhuiYun.project.util.pageUtil.PageResult;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @Author 小江
 * @Description //TODO 订单
 * @Date 10:40 2023/4/4
 **/
@Service
public class orderServiceImpl  implements orderService {
    @Autowired
    orderMapper ordermapper;

    /**
     * @Author 小江
     * @Description //TODO  订单全查（模糊查）
     * @Date 10:40 2023/4/4
     **/
    @Override
    public PageResult orderList(String orderNumber, Integer userId, PageRequest pageResult) {
        if(StringUtils.isEmpty(orderNumber)){
            orderNumber="";
        }
        PageHelper.startPage(pageResult.getPageNum(),pageResult.getPageSize());
        int pageNum = pageResult.getPageNum();

        List<orderModel> handworkDiyModels = ordermapper.orderList(orderNumber,pageResult);
        for(orderModel o :handworkDiyModels){
            o.setAddress(o.getAddressLocationProvince()+o.getAddressLocationCity()+o.getAddressLocationCounty()+o.getAddressDetailed());
        }
        return MybatisPageHelper.getPageResult(handworkDiyModels);
    }

    @Override
    public int dischargedOrder(Integer id) {
        Order order = new Order();
        order.setId(id);
        order.setStatusId(3);
        int i = ordermapper.updateByPrimaryKeySelective(order);
        return i;
    }


}
